var cameraRotationSpeed : float = 15f;		//	camera's rotation speed
var cameraSpeed : float	= 0.07f;			//	camera's movement speed

var waypoint1 : Transform;					//	start point
//var waypoint2 : Transform;				//	not currently used, but may use for arcing movement
var waypoint3 : Transform;					//	end point

var waypointCurrent : int = 1;				// current / last visited waypoint

function Start (){

	// Hide cursor.
	Cursor.visible = false;

	//	Move camera to start position.
	transform.position = waypoint1.position;
}

function Update (){

	//	Camera rotation | default keys: arrows.
	transform.Rotate (0, Input.GetAxis("Horizontal") * cameraRotationSpeed * Time.deltaTime, 0);
	transform.Rotate (Input.GetAxis("Vertical") * cameraRotationSpeed * Time.deltaTime, 0, 0);

	//	Camera movement | default key: left shift / right shift.
	//	First check if key pressed, then where camera is.
	//		Then call MoveCamera function to do relevant movement (wp1 to wp3, or wp3 to wp1).
	if (Input.GetButtonUp("Move") && transform.position.x > 78){ // ie., at waypoint 1
		waypointCurrent = 1;
		MoveCameraAB();
	}
	else if (Input.GetButtonUp("Move") && transform.position.x < -520){ // ie., at waypoint 3
		waypointCurrent = 3;
		MoveCameraBA();
	}
}

function MoveCameraAB () {

	while (waypointCurrent == 1){
		transform.position = Vector3.Lerp(transform.position, waypoint3.position, Time.deltaTime * cameraSpeed);
		yield;
	}
}

function MoveCameraBA () {
	
	while (waypointCurrent == 3){
		transform.position = Vector3.Lerp(transform.position, waypoint1.position, Time.deltaTime * cameraSpeed);
		yield;
	}
}